package com.yanqu.road.server.cmd.activity.wanyao;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WanYaoProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.wanyao.WanYaoModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_WAN_YAO_OPERATE_BOARD, desc = "万妖行操作盘面")
public class WanYaoOperateBoardCmd extends AbstractCommand {

    private int activityId;

    private int operateType;

    private int id;

    private int x;

    private int y;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WanYaoProto.OperateWanYaoBoardReq req = WanYaoProto.OperateWanYaoBoardReq.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        operateType = req.getOperateType();
        id = req.getId();
        x = req.getX();
        y = req.getY();

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (operateType != 1 && operateType !=2){
            ret = GameErrorCode.E_WAN_YAO_ACTIVITY_BLOCK_OPERATE_ERROR;
            return;
        }
        ret = player.getModule(WanYaoModule.class).operateBlock(activityId,operateType, id, x, y);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            WanYaoProto.OperateWanYaoBoardResp.Builder resp = WanYaoProto.OperateWanYaoBoardResp.newBuilder();
            resp.setRet(ret);
            player.sendPacket(ClientProtocol.U_WAN_YAO_OPERATE_BOARD,resp);
        }
    }
}
